﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DeepZoomPivotConstructor;
using DeepZoomPivotConstructor.VisualLib;

namespace t_VisualLib
{
    /// <summary>
    /// Visual isn't actually somethign that can be used directly. But the
    /// base class has a good deal of functionality in it. We do the testing here.
    /// </summary>
    [TestClass]
    public class t_Visual
    {
        public t_Visual()
        {
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        /// <summary>
        /// A dummy class to help us out with testing.
        /// </summary>
        class VisualBasic : Visual
        {
            public override double Width
            {
                get { throw new NotImplementedException(); }
            }

            public override double Height
            {
                get { throw new NotImplementedException(); }
            }

            public override double XPosition
            {
                get
                {
                    throw new NotImplementedException();
                }
                set
                {
                    throw new NotImplementedException();
                }
            }

            public override double YPosition
            {
                get
                {
                    throw new NotImplementedException();
                }
                set
                {
                    throw new NotImplementedException();
                }
            }

            public override void Scale(double factor)
            {
                throw new NotImplementedException();
            }

            public override List<SceneGraphSceneNode> SGNodeList
            {
                get { throw new NotImplementedException(); }
            }

            public override void IncZIndex(int delta)
            {
                throw new NotImplementedException();
            }

            public override int ZIndex
            {
                get { throw new NotImplementedException(); }
            }
        }

        [TestMethod]
        public void TestInitialComposableSetting()
        {
            Visual v = new VisualBasic();
            Assert.IsFalse(v.IsCompositionUnit, "Should be null at start!");
            Assert.IsNull(v.ComposableUnitName, "The composable unit name should be null at the start");
        }

        [TestMethod]
        public void TestSetComposable()
        {
            Visual v = new VisualBasic();
            v.SetAsComposableUnit(v);
            Assert.IsTrue(v.IsCompositionUnit, "Should be a compositianal unit after setting!");
            Assert.AreEqual(v, v.CompositionInfo.MetaData, "The meta data was not set correctly.");
            Assert.IsNotNull(v.ComposableUnitName, "The composable unit name should not be null after setting a CU!");
        }

        [TestMethod]
        public void TestSetComposableWithName()
        {
            Visual v = new VisualBasic();
            v.SetAsComposableUnit(v, "dude");
            Assert.AreEqual("dude", v.ComposableUnitName, "The composable unit name wasn't set correctly");
        }

        [TestMethod]
        public void TestSettingComposableRenderObj()
        {
            Visual v = new VisualBasic();
            v.SetAsComposableUnit(v);
            Assert.IsNull(v.CompositionInfo.RenderObject, "Object should be null when first set");
            v.CompositionInfo.RenderObject = v;
            Assert.AreEqual(v, v.CompositionInfo.RenderObject, "Object was not set!");
        }

        [TestMethod]
        public void TestHierarchicalSimple()
        {
            Visual v = new VisualBasic();
            var allV = v.GetHierarchicalEnumerator(ignore => false);
            Assert.AreEqual(1, allV.Count(), "When hierarchy returns false, expect just the one image");
            var notV = v.GetHierarchicalEnumerator(ignore => true);
            Assert.AreEqual(1, notV.Count(), "When returning true, expect to get back the top one, but nothing else!");
        }

        /// <summary>
        /// Fixed size visual! For testing size code in the visual base class.
        /// </summary>
        private class FixedSizeVisual : Visual
        {
            private double _size;
            public FixedSizeVisual(double sz)
            {
                _size = sz;
            }

            public override double Width
            {
                get { return _size; }
            }

            public override double Height
            {
                get { return _size; }
            }

            public override double XPosition
            {
                get
                {
                    return _size;
                }
                set
                {
                    throw new NotImplementedException();
                }
            }

            public override double YPosition
            {
                get
                {
                    return _size;
                }
                set
                {
                    throw new NotImplementedException();
                }
            }

            public override void Scale(double factor)
            {
                throw new NotImplementedException();
            }

            public override void IncZIndex(int delta)
            {
                throw new NotImplementedException();
            }

            public override int ZIndex
            {
                get { throw new NotImplementedException(); }
            }

            public override List<SceneGraphSceneNode> SGNodeList
            {
                get { throw new NotImplementedException(); }
            }
        }

        [TestMethod]
        public void TestBoundingBox()
        {
            Visual v = new FixedSizeVisual(10.0);
            var bb = v.VisualBoundingBox;

            Assert.AreEqual(10.0, bb.Height, "height isn't right");
            Assert.AreEqual(10.0, bb.Width, "width isn't right");
            Assert.AreEqual(10.0, bb.XPosition, "x position isn't right");
            Assert.AreEqual(10.0, bb.YPosition, "y position isn't right");
        }
    }
}
